package com.esender.search.mq;

import com.esender.common.constant.RabbitMQConstants;
import com.esender.common.model.StandardReport;
import com.esender.search.service.ElasticsearchService;
import com.esender.search.utils.SearchUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class SmsUpdateLogListener {
    @Autowired
    private ElasticsearchService elasticsearchService;
    @RabbitListener(queues = RabbitMQConstants.SMS_GATEWAY_DEAD_QUEUE)
    public void consume(StandardReport standardReport, Channel channel, Message message) throws IOException {
        log.info("【搜素模块-修改日志】 接收到修改日志的消息 report = {}", standardReport);

        Map<String,Object> doc = new HashMap<>();
        doc.put("reportState",standardReport.getReportState());

        elasticsearchService.update(SearchUtils.INDEX + SearchUtils.getYear(),standardReport.getSequenceId().toString(),doc);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


}
